/*
 * NdaraiSMSBackupView.java
 */
package ndaraismsbackup;

import java.sql.*;
import java.io.File;
import org.w3c.dom.*;
import java.io.FileWriter;
import javax.swing.JFrame;
import javax.xml.parsers.*;
import javax.swing.JDialog;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.transform.*;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.swing.JFileChooser;
import javax.xml.transform.dom.*;
import java.text.SimpleDateFormat;
import com.trilead.ssh2.SCPClient;
import com.trilead.ssh2.Connection;
import javax.xml.transform.stream.*;
import java.io.BufferedOutputStream;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.SingleFrameApplication;

import java.awt.*;


/**
 * The application's main frame.
 */
public class NdaraiSMSBackupView extends FrameView {

    public NdaraiSMSBackupView(SingleFrameApplication app) {
        super(app);

        initComponents();

        /*
         * Set default settings
         */
        txtHost.setText("192.168.0.101");
        txtUserName.setText("root");
        txtPassword.setText("alpine");
        txtLocation.setText(System.getProperty("user.dir")+"\\MyBackup");
        rbBackupAll.setSelected(true);
        rbStyledXML.setSelected(true);
        chkDebug.setSelected(false);
        mainPanel.setSize(200, 300);
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = NdaraiSMSBackupApp.getApplication().getMainFrame();
            aboutBox = new NdaraiSMSBackupAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        NdaraiSMSBackupApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        btnClose = new javax.swing.JButton();
        btnBeginBackup = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        chkDebug = new javax.swing.JCheckBox();
        jLabel6 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtHost = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtPassword = new javax.swing.JTextField();
        txtUserName = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        rbBackupAll = new javax.swing.JRadioButton();
        txtContactAddress = new javax.swing.JTextField();
        rbBackupSpecified = new javax.swing.JRadioButton();
        jLabel10 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        rbPlainTXT = new javax.swing.JRadioButton();
        rbSQLiteDB = new javax.swing.JRadioButton();
        rbStyledXML = new javax.swing.JRadioButton();
        jLabel5 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        txtLocation = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        btnBrowse = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        bgBackupType = new javax.swing.ButtonGroup();
        bgBackupFormat = new javax.swing.ButtonGroup();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ndaraismsbackup.NdaraiSMSBackupApp.class).getContext().getResourceMap(NdaraiSMSBackupView.class);
        btnClose.setText(resourceMap.getString("btnClose.text")); // NOI18N
        btnClose.setName("btnClose"); // NOI18N
        btnClose.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                closeApplication(evt);
            }
        });

        btnBeginBackup.setText(resourceMap.getString("btnBeginBackup.text")); // NOI18N
        btnBeginBackup.setName("btnBeginBackup"); // NOI18N
        btnBeginBackup.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                beginBackup(evt);
            }
        });

        jSeparator1.setName("jSeparator1"); // NOI18N

        chkDebug.setText(resourceMap.getString("chkDebug.text")); // NOI18N
        chkDebug.setName("chkDebug"); // NOI18N

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        txtHost.setText(resourceMap.getString("txtHost.text")); // NOI18N
        txtHost.setName("txtHost"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        txtPassword.setText(resourceMap.getString("txtPassword.text")); // NOI18N
        txtPassword.setName("txtPassword"); // NOI18N

        txtUserName.setText(resourceMap.getString("txtUsername.text")); // NOI18N
        txtUserName.setName("txtUsername"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(26, 26, 26)
                        .addComponent(txtHost, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(26, 26, 26)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(12, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtHost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel2.setName("jPanel2"); // NOI18N

        bgBackupType.add(rbBackupAll);
        rbBackupAll.setText(resourceMap.getString("rbBackupAll.text")); // NOI18N
        rbBackupAll.setName("rbBackupAll"); // NOI18N
        rbBackupAll.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                validateBackupSettings(evt);
            }
        });

        txtContactAddress.setText(resourceMap.getString("txtAddress.text")); // NOI18N
        txtContactAddress.setName("txtAddress"); // NOI18N

        bgBackupType.add(rbBackupSpecified);
        rbBackupSpecified.setText(resourceMap.getString("rbBackupSpecified.text")); // NOI18N
        rbBackupSpecified.setName("rbBackupSpecified"); // NOI18N
        rbBackupSpecified.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                validateBackupSettings(evt);
            }
        });

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(10, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rbBackupAll)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(rbBackupSpecified)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtContactAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rbBackupAll)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(rbBackupSpecified)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtContactAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jPanel3.setName("jPanel3"); // NOI18N

        bgBackupFormat.add(rbPlainTXT);
        rbPlainTXT.setText(resourceMap.getString("rbPlainTXT.text")); // NOI18N
        rbPlainTXT.setName("rbPlainTXT"); // NOI18N
        rbPlainTXT.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                validateBackupFormat(evt);
            }
        });

        bgBackupFormat.add(rbSQLiteDB);
        rbSQLiteDB.setText(resourceMap.getString("rbSQLiteDB.text")); // NOI18N
        rbSQLiteDB.setName("rbSQLiteDB"); // NOI18N
        rbSQLiteDB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                validateBackupFormat(evt);
            }
        });

        bgBackupFormat.add(rbStyledXML);
        rbStyledXML.setSelected(true);
        rbStyledXML.setText(resourceMap.getString("rbStyledXML.text")); // NOI18N
        rbStyledXML.setName("rbStyledXML"); // NOI18N
        rbStyledXML.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                validateBackupFormat(evt);
            }
        });

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rbPlainTXT)
                            .addComponent(rbStyledXML)
                            .addComponent(rbSQLiteDB))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addGap(5, 5, 5)
                .addComponent(rbStyledXML)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbPlainTXT)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(rbSQLiteDB)
                .addGap(12, 12, 12))
        );

        jPanel4.setName("jPanel4"); // NOI18N

        txtLocation.setText(resourceMap.getString("txtLocation.text")); // NOI18N
        txtLocation.setName("txtLocation"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        btnBrowse.setText(resourceMap.getString("btnBrowse.text")); // NOI18N
        btnBrowse.setName("btnBrowse"); // NOI18N
        btnBrowse.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                browseForLocation(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnBrowse)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addGap(2, 2, 2)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBrowse))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(btnClose)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(chkDebug)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBeginBackup)))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnClose)
                    .addComponent(btnBeginBackup)
                    .addComponent(chkDebug))
                .addGap(132, 132, 132))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(ndaraismsbackup.NdaraiSMSBackupApp.class).getContext().getActionMap(NdaraiSMSBackupView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    private void closeApplication(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_closeApplication

        if (evt.getSource() == btnClose) {
            //Close Application
            System.exit(0);
        }
    }//GEN-LAST:event_closeApplication

    private void beginBackup(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_beginBackup
        boolean isSuccess = true;

        Cursor hourglassCursor = new Cursor(Cursor.WAIT_CURSOR);
        mainPanel.setCursor(hourglassCursor);

        if (chkDebug.isSelected()){
            ShowVerboseDialogBox();
            debugDialog.setCursor(hourglassCursor);
        }

        try{
            if (evt.getSource() == btnBeginBackup) {
                
                String strLocation;

                //Validate Location
                strLocation = txtLocation.getText();

                File dir = new File(strLocation);

                if (!dir.exists()) {
                    dir.mkdir();
                    printDebug("Creating directory: " + strLocation );
                }


                //Which Backup Format?

                //*** SQLite DB ***
                if (rbSQLiteDB.isSelected()){
                    printDebug("** Saving as SQLite DB");

                    //Get sms.db file - and save to user specified location
                    isSuccess = saveAsSQLiteDB(
                            txtHost.getText(),
                            txtUserName.getText(),
                            txtPassword.getText(),
                            strLocation + "\\sms.db");
                }
                //*** Plain Text ***
                else if (rbPlainTXT.isSelected()){
                    printDebug("** Saving as TXT");

                    //Get sms.db file
                    isSuccess = saveAsSQLiteDB(
                        txtHost.getText(),
                        txtUserName.getText(),
                        txtPassword.getText(),
                        internalDBLocation);

                    if (isSuccess) {
                        isSuccess = saveAsTXT(strLocation + "\\Ndara.txt");
                    }
                    else {
                        printDebug("FAILED: Saving as TXT");
                    }
                }
                //*** Styled XML ***
                else if (rbStyledXML.isSelected()){
                    printDebug("** Saving as Styled XML");

                    //Get sms.db file
                    isSuccess = saveAsSQLiteDB(
                        txtHost.getText(),
                        txtUserName.getText(),
                        txtPassword.getText(),
                        internalDBLocation);

                    if (isSuccess) {
                        isSuccess = saveAsXML(strLocation);
                    }
                    else{
                        printDebug("FAILED: Saving as Styled XML");
                    }
                }
            } //!file.exists

            if (isSuccess){
                printDebug("BACKUP SUCCESSFUL.");
                JOptionPane.showMessageDialog(
                        mainPanel,
                        "Backup Successful!",
                        "Backup Status",
                        JOptionPane.INFORMATION_MESSAGE
                );
            }
            else{
                printDebug("BACKUP FAILED.");
                JOptionPane.showMessageDialog(
                        mainPanel,
                        "Backup Failed!",
                        "Backup Status",
                        JOptionPane.INFORMATION_MESSAGE
                );
            }
            
        }
        catch (Exception ex) {
            printDebug("Error: " + ex.toString());
            showErrorDialog("An error occoured. Backup Failed!\n " + ex.toString());
        }

        Cursor normalCursor  = new Cursor(Cursor.DEFAULT_CURSOR);
        mainPanel.setCursor(normalCursor );
        if (chkDebug.isSelected()){
            debugDialog.setCursor(normalCursor);
        }

    }//GEN-LAST:event_beginBackup

    private void browseForLocation(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browseForLocation
        //Browse for Folder
        if (evt.getSource() == btnBrowse) {
            jfcBrowse.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = jfcBrowse.showOpenDialog(mainPanel);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = jfcBrowse.getSelectedFile();
                txtLocation.setText(file.getPath());
            }
        }
}//GEN-LAST:event_browseForLocation

    private void validateBackupSettings(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_validateBackupSettings
        
        //Backup ALL
        if (evt.getSource() == rbBackupAll){
            txtContactAddress.setEnabled(false);
            rbSQLiteDB.setEnabled(true);
        }
        //Backup Single Contact
        else if(evt.getSource() == rbBackupSpecified){
            txtContactAddress.setEnabled(true);
            rbSQLiteDB.setEnabled(false);
        }
    }//GEN-LAST:event_validateBackupSettings

    private void validateBackupFormat(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_validateBackupFormat
        
        //SQLite DB
        if (evt.getSource() == rbSQLiteDB){
            rbBackupSpecified.setEnabled(false);
        }
        //Plain Text
        else if(evt.getSource() == rbPlainTXT){
            rbBackupSpecified.setEnabled(true);
        }
        //Backup Single Contact
        else if(evt.getSource() == rbStyledXML){
            rbBackupSpecified.setEnabled(true);
        }
    }//GEN-LAST:event_validateBackupFormat

    private boolean saveAsSQLiteDB(String host, String user, String pass, String location) {

        SCPClient scp;
        boolean isSuccess = true;
        String remoteFile = "/private/var/mobile/Library/SMS/sms.db";
        String localFile = location;

        Connection conn = new Connection(host);

        printDebug("Starting SSH Connection");

        try {
            conn.connect();
        } catch (IOException ex) {
            isSuccess = false;
            printDebug("IOExeption connecting:" + ex.toString());
            showErrorDialog("Cannot connect to your iPhone. Check the following: \n " +
                    "- Do you have a jailbroken iPhone 3g with SSH installed?" +
                    "- Is your iPhone and Computer on the same network?\n " +
                    "- Ensure you connected to WIFI. Check for the WIFI icon.\n " +
                    "- Turn off 3G. If the 3G is enabled the iPhone can flip between WIFI and 3G.\n " +
                    "- Check the IP address for your iPhone at:\n" +
                    "    Settings > General > Network > WIFI > (your network)\n ");
        }
        
        try {
            if (conn.authenticateWithPassword(user, pass)) {
                printDebug("Authentication Success");
            } else {
                isSuccess = false;
                printDebug("Authentication Failed!");
                showErrorDialog("SSH Authentication Failed. Check the username and password");
            }
        } catch (IOException ex) {
            isSuccess = false;
            printDebug("Exception during authentication:" + ex.toString());
            showErrorDialog("There was an error during the SSH authentication.\n " + ex.toString());
        }

        try {
            scp = conn.createSCPClient();
            printDebug("Client created.");

            try {
                printDebug("Copying File to" + localFile);

                BufferedOutputStream bos = new BufferedOutputStream(
                        new FileOutputStream(localFile, false));
                scp.get(remoteFile, bos);
                bos.flush();
                bos.close();

                printDebug("-- SQLite DB File Copied!");

            } catch (IOException ex) {
                isSuccess = false;
                printDebug("Error copying SQLite DB file:\n" + ex.toString());
                showErrorDialog("An error occoured while saving the SQLite DB file.\n " + ex.toString());
            }

        } catch (IOException ex) {
            isSuccess = false;
            printDebug("Error creating SCP Client\n" + ex.toString());
            showErrorDialog("An error occoured while connecting to the iPhone.\n " + ex.toString());
        }

        conn.close();
        printDebug("SCP Connection Closed.");
        return isSuccess;
    }

    private boolean saveAsTXT(String location){

        boolean isSuccess = true;
        ResultSet rsMessage;
        ResultSet rsMsgGroup;
        String query;
        try {
            Class.forName("org.sqlite.JDBC");

            printDebug("Connecting to DB");

            java.sql.Connection conn
                    = DriverManager.getConnection("jdbc:sqlite:/"
                    + internalDBLocation);
            Statement stat1 = conn.createStatement();
            Statement stat2 = conn.createStatement();

            query = "SELECT DISTINCT address FROM message";
            
            //Append WHERE if this is a single contact backup
            if (rbBackupSpecified.isSelected()){ 
                query += " WHERE address='" + txtContactAddress.getText() + "'";
            }
            
            rsMsgGroup = stat1.executeQuery(query);
                        
            BufferedWriter out = new BufferedWriter(new FileWriter(location));
            printDebug("-- Writing to TXT");

            while (rsMsgGroup.next()){
                out.newLine();
                out.write("-----------------------------------------------");
                out.newLine();
                out.write(rsMsgGroup.getString("address"));
                out.newLine();
                out.write("-----------------------------------------------");
                out.newLine();

                printDebug("Address: " + rsMsgGroup.getString("address"));

                rsMessage = stat2.executeQuery(
                        "SELECT * FROM message WHERE address='" 
                        + rsMsgGroup.getString("address") 
                        + "'" );
                
                while (rsMessage.next()) {
                    
                    printDebug("Msg ID: " + rsMessage.getInt("ROWID"));

                    if (rsMessage.getInt("flags") == 2){ //Incoming SMS
                      out.write("==>    :  ");
                    }
                    else if (rsMessage.getInt("flags") == 3){ //Outgoing SMS
                        out.write("<==    :  ");
                    }
                    else {
                        out.write("***    :  ");
                    }
                    
                    out.write(messageDate(rsMessage.getString("date")));
                    out.newLine();
                    out.write(rsMessage.getString("text"));
                    out.newLine();
                    out.newLine();
                }

                rsMessage.close();
                out.write("***********************************************");
                out.newLine();
                out.newLine();
                out.newLine();
            }

            //Ad Banner
            out.write("#####################################################");
            out.newLine();
            out.write("Created with: ");
            out.newLine();
            out.write("Ndara iSMS Backup (http://code.google.com/p/ndara/)");
            out.newLine();
            out.write("#####################################################");

            rsMsgGroup.close();
            out.close();
            conn.close();
        }
        catch (IOException e) {
            isSuccess = false;
            printDebug("Error writing Text File: \n" + e.toString());
            showErrorDialog("An error occoured while saving the TXT file.\n " + e.toString());
        }
        catch (Exception ex) {
            isSuccess = false;
            printDebug("DB Error: \n" + ex.toString());
            showErrorDialog("A database error occoured.\n " + ex.toString());
        }

        return isSuccess;
    }

    private boolean saveAsXML(String location){

        boolean isSuccess = true;
        ResultSet rsMessage;
        ResultSet rsMsgGroup;
        ResultSet rsSummary;

        String query; 
        try {
            Class.forName("org.sqlite.JDBC");

            printDebug("Connecting to DB.");
            java.sql.Connection conn
                    = DriverManager.getConnection("jdbc:sqlite:/"
                    + internalDBLocation);

            printDebug("-- Creating Individual XMLs");

            //////////////////////////
            // Create Individual XMLs
            Statement stat1 = conn.createStatement();
            Statement stat2 = conn.createStatement();
            
            query = "SELECT DISTINCT address FROM message ";
            
            //Append WHERE if this is a single contact backup
            if (rbBackupSpecified.isSelected()){ 
                query += " WHERE address='" + txtContactAddress.getText() + "'";
            }

            //Get list of contacts
            rsMsgGroup = stat1.executeQuery( query );

            while (rsMsgGroup.next()){

                printDebug("Get SMSs from: " + rsMsgGroup.getString("address"));
                
                //get messages from contact
                rsMessage = stat2.executeQuery(
                        "SELECT * FROM message WHERE address='"
                        + rsMsgGroup.getString("address")
                        + "'" );

                //Generate Message XML for each contact's messages.
                writeMessageXML(rsMsgGroup.getString("address"), 
                        rsMessage,
                        location);
            }
            
            //////////////////////////
            // Create Summary XML
            if (rbBackupAll.isSelected()){
                
                printDebug("-- Create Summary XML");

                Statement stat3 = conn.createStatement();

                //get messages from contact
                rsSummary = stat3.executeQuery(
                        "SELECT text, date, address" +
                        " FROM msg_group INNER JOIN message" +
                        " ON msg_group. newest_message = message.ROWID" +
                        " ORDER BY date DESC" );
                writeSummaryXML(rsSummary, location);
            }

            //////////////////////////
            // Copy Include Folder
            printDebug("-- Copy Include Folder");

            File internalIncludeLocation 
                    = new File(System.getProperty("user.dir")
                    + "\\Include\\");
            //Target Location
            File backupLocation = new File(location + "\\Include\\");

            printDebug("Copying Include Dir to:" + location + "\\Include\\");
            copyDirectory(internalIncludeLocation,backupLocation);
        }
        catch (Exception ex) {
            isSuccess = false;
            printDebug("DB Error: \n" + ex.toString());
            showErrorDialog("A database error occoured.\n " + ex.toString());
        }
        
        return isSuccess;
    }

    private void writeMessageXML(String contactAddress, ResultSet rsMessage,String location){
        try {
            /*
            <?xml version="1.0" encoding="UTF-8"?>
            <?xml-stylesheet type="text/xsl" href="include/message.xsl" ?>
            <contact address="1234567890">
                <sms timeStamp="2009-2-4 16:00" type="1">content sent1</sms>
                <sms timeStamp="2009-2-4 16:13" type="2">content received1</sms>
                <sms timeStamp="2009-2-4 16:37" type="1">content sent2</sms>
                <sms timeStamp="2009-2-4 16:44" type="2">content received2</sms>
            </contact>
             */

            /////////////////////////////
            //Create an empty XML Document
            DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
            Document doc = docBuilder.newDocument();
            
            ////////////////////////
            //Add StyleSheet
            ProcessingInstruction pi = 
                    doc.createProcessingInstruction("xml-stylesheet",
                    "type=\"text/xsl\" href=\"include/message.xsl\"");
            doc.appendChild(pi);

            ////////////////////////
            //Creating the XML tree

            //create the root element and add it to the document
            /*<contact address="1234567890">*/
            Element root = doc.createElement("contact");
            doc.appendChild(root);
            root.setAttribute("address", contactAddress);
            Comment CommentAD = doc.createComment("Generated with: " +
                    "Ndara iSMS Backup (http://code.google.com/p/ndara/)");
            doc.appendChild(CommentAD);

            //Iterate though each message
            while (rsMessage.next()) {
                /*<sms timeStamp="2009-2-4 16:37" type="1">content sent2</sms>*/

                printDebug("SMS ID: " + rsMessage.getString("ROWID"));

                //create child element, add an attribute, and add to root
                Element child = doc.createElement("sms");
                child.setAttribute("timeStamp",
                        messageDate(rsMessage.getString("date")));
                child.setAttribute("type",
                        rsMessage.getString("flags"));
                root.appendChild(child);

                //add a text element to the child
                Text text = doc.createTextNode(rsMessage.getString("text"));
                child.appendChild(text);

            }

            /////////////////
            //Output the XML

            //set up a transformer
            TransformerFactory transfac = TransformerFactory.newInstance();
            Transformer trans = transfac.newTransformer();
            trans.setOutputProperty(OutputKeys.INDENT, "yes");

            //create string from xml tree
            File fSMS = new File(location+"\\"+contactAddress+".xml");
            StreamResult result = new StreamResult(fSMS);
            DOMSource source = new DOMSource(doc);

            trans.transform(source, result);

            printDebug("## Saved To: " + location+"\\"+contactAddress+".xml");

        }
        catch (TransformerException tex){
            printDebug("XML Transformer Error: \n" + tex.toString());
            showErrorDialog("An error occoured while building the XML.\n " + tex.toString());
        }
        catch (ParserConfigurationException pex){
            printDebug("XML Parser Error: \n" + pex.toString());
            showErrorDialog("An error occoured while building the XML.\n " + pex.toString());
        }
        catch (SQLException sex){
            printDebug("DB Error: \n" + sex.toString());
            showErrorDialog("A Database error has occoured.\n " + sex.toString());
        }
        catch (Exception ex){
            showErrorDialog("An error has occoured.\n " + ex.toString());
        }
    }

    private void writeSummaryXML(ResultSet rsSummary, String location){
    try {
            /*
            <?xml version="1.0" encoding="utf-8"?>
            <?xml-stylesheet type="text/xsl" href="include/summary.xsl" ?>
            <summary>
              <contact address="1234567890" dateStamp="07/02/09" >
                <sms>content sent1</sms>
                </contact>
              <contact address="0987654322" dateStamp="02/02/09" >
                <sms>my previous message was nothing ignore</sms>
              </contact>
            </summary>
             */

            /////////////////////////////
            //Create an empty XML Document
            DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
            Document doc = docBuilder.newDocument();

            ////////////////////////
            //Add StyleSheet
            ProcessingInstruction pi =
                    doc.createProcessingInstruction("xml-stylesheet",
                    "type=\"text/xsl\" href=\"include/summary.xsl\"");
            doc.appendChild(pi);
            
            //Ndara Ad 
            Comment CommentAD = doc.createComment("Generated with: " +
                    "Ndara iSMS Backup (http://code.google.com/p/ndara/)");
            doc.appendChild(CommentAD);

            ////////////////////////
            //Creating the XML tree

            //create the root element and add it to the document
            /*<contact address="1234567890">*/
            Element root = doc.createElement("summary");
            doc.appendChild(root);

            //Iterate though each message
            while (rsSummary.next()) {
                /*<contact address="0987654322" dateStamp="02/02/09">*/

                printDebug("Address: " + rsSummary.getString("address"));

                //create child element, add an attribute, and add to root
                Element child = doc.createElement("contact");
                child.setAttribute("address",
                        rsSummary.getString("address"));
                child.setAttribute("dateStamp",
                        summaryDate(rsSummary.getString("date")));

                root.appendChild(child);

                /*<sms>my previous message was nothing ignore</sms>*/
                Element eSMS = doc.createElement("sms");

                String smsText = rsSummary.getString("text");
                //Trim sms text to 65 chars
                if (smsText.length() > 65) {
                    smsText = smsText.substring(0, 65) + "...";
                }
                Text text = doc.createTextNode(smsText );
                eSMS.appendChild(text);
                child.appendChild(eSMS);
            }

            /////////////////
            //Output the XML

            //set up a transformer
            TransformerFactory transfac = TransformerFactory.newInstance();
            Transformer trans = transfac.newTransformer();
            trans.setOutputProperty(OutputKeys.INDENT, "yes");

            //create string from xml tree
            File fSMS = new File(location+"\\summary.xml");
            StreamResult result = new StreamResult(fSMS);
            DOMSource source = new DOMSource(doc);
            trans.transform(source, result);

            printDebug("## Saved To: " + location+"\\summary.xml");
        }
        catch (TransformerException tex){
            printDebug("XML Transformer Error: \n" + tex.toString());
            showErrorDialog("An error occoured while building the XML.\n " + tex.toString());
        }
        catch (ParserConfigurationException pex){
            printDebug("XML Parser Error: \n" + pex.toString());
            showErrorDialog("An error occoured while building the XML.\n " + pex.toString());
        }
        catch (SQLException sex){
            printDebug("DB Error: \n" + sex.toString());
            showErrorDialog("A Database error has occoured.\n " + sex.toString());
        }
        catch (Exception ex){
            showErrorDialog("An error has occoured.\n " + ex.toString());
        }
    }

    private void copyDirectory(File srcPath,File dstPath) throws IOException{
        try {
            if (srcPath.isDirectory()){ //This is a Directory

                //Create directory if it doesnt exist
                if (!dstPath.exists()){
                    dstPath.mkdir();
                }

                //Get list of files and recursively copy.
                String files[] = srcPath.list();
                for(int i = 0; i < files.length; i++){
                    copyDirectory(new File(srcPath, files[i]),
                    new File(dstPath, files[i]));
                }
            }
            else { //This is a File
                if(!srcPath.exists()){ //Path must exist
                    printDebug("Error copying Include. Sub path does not exist!");
                    showErrorDialog("An error occoured while copying supporting files.");
                }
                else
                {
                    InputStream in = new FileInputStream(srcPath);
                    OutputStream out = new FileOutputStream(dstPath);

                    // Transfer bytes from in to out
                    byte[] buf = new byte[1024];
                    int len;

                    while ((len = in.read(buf)) > 0) {
                        out.write(buf, 0, len);
                    }
                    in.close();
                    out.close();
                }
            }
        }
        catch (Exception ex){
            showErrorDialog("An error has occoured.\n " + ex.toString());
        }            
    }

    private String messageDate(String epochDate){
        //20-jan-09 14:00
        try {
            Date dtSMS = new Date(Long.parseLong(epochDate) * 1000);
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy HH:mm");
            return sdf.format(dtSMS);
        }
        catch( Exception ex){
            printDebug("Date Conversion Error: \n" + ex.toString());
            return "(error)";
        } 
    }

    private String summaryDate(String epochDate){
        //20/01/09
        try {
            Date dtSMS = new Date(Long.parseLong(epochDate) * 1000);
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy");
            return sdf.format(dtSMS);
        }
        catch( Exception ex){
            printDebug("Date Conversion Error: \n" + ex.toString());
            return "(error)";
        }
    }

    private void printDebug(String message){
        if (chkDebug.isSelected()){
            txtAreaDebug.append( message + "\n" );
        }
    }

    private void showErrorDialog(String errMsg){

            JOptionPane.showMessageDialog(
                        mainPanel,
                        errMsg,
                        "ERROR!",
                        JOptionPane.ERROR_MESSAGE
            );

            Cursor normalCursor  = new Cursor(Cursor.DEFAULT_CURSOR);
            mainPanel.setCursor(normalCursor );
            if (chkDebug.isSelected()){
                debugDialog.setCursor(normalCursor);
            }
    }

    protected void ShowVerboseDialogBox() {
        JFrame mainFrame = NdaraiSMSBackupApp.getApplication().getMainFrame();
        debugDialog = new Dialog(mainFrame,"Verbose Output",false);
        FlowLayout layout = new FlowLayout();
        debugDialog.setLayout(layout);

        javax.swing.JButton button = new javax.swing.JButton("Close");
        button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                closeDialog(evt);
            }
        });

        txtAreaDebug.setEditable(false);
        //txtAreaDebug.setLineWrap(true);

        debugDialog.add(txtAreaDebug);
        debugDialog.add(button);
        debugDialog.setSize(300, 200);

        debugDialog.setLocationRelativeTo(mainPanel);
        debugDialog.isValid();
        debugDialog.setVisible(true);

    }

    private void closeDialog(java.awt.event.MouseEvent evt){
        debugDialog.dispose();
    }

    private Dialog debugDialog;
    private TextArea txtAreaDebug 
            = new TextArea("", 7, 35, TextArea.SCROLLBARS_VERTICAL_ONLY);

    private JDialog aboutBox;
    private JFileChooser jfcBrowse = new JFileChooser();
    private final String internalDBLocation
        = System.getProperty("user.dir") + "\\Ndara.db";

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgBackupFormat;
    private javax.swing.ButtonGroup bgBackupType;
    private javax.swing.JButton btnBeginBackup;
    private javax.swing.JButton btnBrowse;
    private javax.swing.JButton btnClose;
    private javax.swing.JCheckBox chkDebug;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JRadioButton rbBackupAll;
    private javax.swing.JRadioButton rbBackupSpecified;
    private javax.swing.JRadioButton rbPlainTXT;
    private javax.swing.JRadioButton rbSQLiteDB;
    private javax.swing.JRadioButton rbStyledXML;
    private javax.swing.JTextField txtContactAddress;
    private javax.swing.JTextField txtHost;
    private javax.swing.JTextField txtLocation;
    private javax.swing.JTextField txtPassword;
    private javax.swing.JTextField txtUserName;
    // End of variables declaration//GEN-END:variables
}
